﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.BLL;
using Aij1.Model;
using Aij1.Cms;
using Aij1.Utils;
using System.Web.UI.HtmlControls;

namespace Aij1
{
    /// <summary>
    /// 单件商品展示页
    /// </summary>
    public partial class ShopDetails : BasePage
    {
        IList<A_Category> newsCat;
        int catId;
        protected B_Series Article;
        protected string PrevLink, NextLink;

        protected void Page_Load(object sender, EventArgs e)
        {
            int newsId = CommOp.ToInt(Request.QueryString["Id"]);
            if (newsId > 0)
            {
                Article = XpoSession.GetObjectByKey<B_Series>(newsId);
            }

            if (Article == null || (Article.Status != ArticleStatusType.审核通过 && CurrentUser == null))
            {
                Response.Write("没有找到此Id对应的商品.");
                Response.End();
            }

            catId = Article.CategoryId == null ? 0 : Article.CategoryId.Oid;
            A_Article prevNews = ArticleData.GetPrevNews(Article, ArticleType.商品);

            if (prevNews == null)
            {
                PrevLink = String.Format("<a href='Shop_{0}.htm'>回到列表</a>", catId);
            }
            else
            {
                PrevLink = String.Format("<a href='{0}'>{1}</a>", QBind.GetArticlePage(prevNews.AType, prevNews.Oid), prevNews.Title);
            }

            A_Article nextNews = ArticleData.GetNextNews(Article, ArticleType.商品);

            if (nextNews == null)
            {
                NextLink = String.Format("<a href='Shop_{0}.htm'>回到列表</a>", catId);
            }
            else
            {
                NextLink = String.Format("<a href='{0}'>{1}</a>", QBind.GetArticlePage(nextNews.AType, nextNews.Oid), nextNews.Title);
            }

            PageName = Article.Title;
            Keywords = Article.Keywords;
            Description = CommOp.CutStr(Article.Intro, 100);
        }

        protected int GetCssClassIndex(object oid)
        {
            return (int)oid == catId ? 1 : 2;
        }
    }
}